﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using PBO.Data;

namespace PBO.Game.BattleClass
{
    public partial class Pokemon
    {
        private long mImage1;
        private long mImage2;
        private long mImage1b;
        private long mImage2b;
        private long mIcon;
        private long mFrame1;
        private long mFrame2;

        private void LoadImage(PokemonData data)
        {
            mImage1 = data.FrontImage;
            mImage1b = data.FrontImageF;
            mImage2 = data.BackImage;
            mImage2b = data.BackImageF;
            mIcon = data.Icon;
            mFrame1 = data.Frame;
            mFrame2 = data.FrameF;
        }

        public Bitmap FrontImage
        {
            get
            {
                var _with1 = BattleState;
                if (_with1.substituted)
                    return Properties.Resources.Substitute;
                if (_with1.transfrom)
                {
                    if (Gender == PokemonGender.Female && _with1.transTemp.FrontImageF != -1)
                    {
                        return GetImage(_with1.transTemp.FrontImageF);
                    }
                    else
                    {
                        return GetImage(_with1.transTemp.FrontImage);
                    }
                }
                if (GetSelTrait() == Trait.Forecast && _with1.traitRaised)
                    return _with1.tempImg1;
                if (Gender == PokemonGender.Female)
                    return FrontImageF;
                return GetImage(mImage1);
            }
            set
            {
                BattleState.tempImg1 = value;
                OnImageChanged();
            }
        }
        public Bitmap BackImage
        {
            get
            {
                var _with2 = BattleState;
                if (_with2.substituted)
                    return Properties.Resources.SubBack;

                if (_with2.transfrom)
                {
                    if (Gender == PokemonGender.Female && _with2.transTemp.FrontImageF != -1)
                    {
                        return GetImage(_with2.transTemp.BackImageF);
                    }
                    else
                    {
                        return GetImage(_with2.transTemp.BackImage);
                    }
                }
                if (GetSelTrait() == Trait.Forecast && _with2.traitRaised)
                    return _with2.tempImg2;
                if (Gender == PokemonGender.Female)
                {
                    return BackImageF;
                }
                return GetImage(mImage2);
            }
            set
            {
                BattleState.tempImg2 = value;
                OnImageChanged();
            }
        }
        public Bitmap FrontImageF
        {
            get
            {
                if (mImage1b != -1)
                    return GetImage(mImage1b);
                return GetImage(mImage1);
            }
        }
        public Bitmap BackImageF
        {
            get
            {
                if (mImage2b != -1)
                    return GetImage(mImage2b);
                return GetImage(mImage2);
            }
        }
        public Bitmap Icon
        {
            get
            {
                if (BattleState.transfrom)
                    return GetImage(BattleState.transTemp.Icon);
                return GetImage(mIcon);
            }
        }
        public Bitmap Frame
        {
            get
            {
                if (Gender == PokemonGender.Female)
                    return FrameF;
                if (mFrame1 != -1)
                    return GetImage(mFrame1);
                return FrontImage;
            }
        }
        public Bitmap FrameF
        {
            get
            {
                if (mFrame2 != -1)
                    return GetImage(mFrame2);
                if (mFrame1 != -1)
                    return GetImage(mFrame1);
                return FrontImage;
            }
        }
        private Bitmap GetImage(long position)
        {
            return GameService.GetImage(this.Data.Id, position);
        }
    }
}
